from selenium.webdriver.common.by import By

from common.Utills import BlogDriver


#测试博客详情页

class BlogDetail:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=84585"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
    #博客详情页测试
    def DetailTestByLogin(self):
        print("当前用户发布博客详情页测试:\n")
        #检查标题
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.right > div > div.title')
        if elements:
            print("标题存在")
        else:
            print("标题不存在")
        #检查时间
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.right > div > div.date')
        if elements:
            print("时间存在")
        else:
            print("时间不存在")
        #检查内容
        elements = self.driver.find_elements(By.CSS_SELECTOR,"#h2-u5728u8FD9u91CCu5199u4E0Bu4E00u7BC7u535Au5BA2 > a")
        if elements:
            print("内容存在")
        else:
            print("内容不存在")
        #检查编辑按钮
        elements = self.driver.find_elements(By.CSS_SELECTOR, "body > div.container > div.right > div > div.operating > button:nth-child(1)")
        if elements:
            print("编辑按钮存在")
        else:
            print("编辑按钮不存在")
        # 检查删除按钮
        elements = self.driver.find_elements(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)")
        if elements:
            print("删除按钮存在")
        else:
            print("删除按钮不存在")
        #屏幕截图
        BlogDriver.getScreeShont()
        print("其他用户发布博客详情页测试:\n")
        self.driver.get("http://8.137.19.140:9090/blog_detail.html?blogId=84582")
        elements = self.driver.find_elements(By.CSS_SELECTOR, 'body > div.container > div.right > div > div.title')
        if elements:
            print("标题存在")
        else:
            print("标题不存在")
        # 检查时间
        elements = self.driver.find_elements(By.CSS_SELECTOR, 'body > div.container > div.right > div > div.date')
        if elements:
            print("时间存在")
        else:
            print("时间不存在")
        # 检查内容
        elements = self.driver.find_elements(By.CSS_SELECTOR, "#h2-u5728u8FD9u91CCu5199u4E0Bu4E00u7BC7u535Au5BA2 > a")
        if elements:
            print("内容存在")
        else:
            print("内容不存在")
        # 检查编辑按钮
        elements = self.driver.find_elements(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(1)")
        if elements:
            print("编辑按钮存在")
        else:
            print("编辑按钮不存在")
        # 检查删除按钮
        elements = self.driver.find_elements(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)")
        if elements:
            print("删除按钮存在")
        else:
            print("删除按钮不存在")

